package com.example.springLearning.part9.controller;

import com.example.springLearning.part9.config.MyEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@Slf4j
@RequestMapping("/spring/part9")
public class Spring9Controller2 {

    @Autowired
    private AbstractApplicationContext abstractApplicationContext;

    @RequestMapping(path = "publishEvent2", method = RequestMethod.GET)
    public String notifyEvent() {
        log.info("start to publish event");
        abstractApplicationContext.publishEvent(new MyEvent(UUID.randomUUID()));
        return "ok";
    }
}
